﻿using System;
using System.Windows.Media;
using PostProcGUI.Model;
using System.Xml.Serialization;

namespace PostProcGUI.ModelView.ForModel
{
    public class ColorLevelViewModel : ViewModelBase
    {
        #region Поля

        private ColorLevel _colorLevel = new ColorLevel();

        #endregion // Поля

        #region // Свойства

        [XmlElement]
        public Brush Color
        {
            get { return new SolidColorBrush(_colorLevel.Color); }
            set
            {
                _colorLevel.Color = ((SolidColorBrush)value).Color;
                OnPropertyChanged("Color");
            }
        }

        public string ColorHex
        {
            get { return _colorLevel.Color.ToString(); }
        }

        [XmlElement]
        public string Value
        {
            get { return _colorLevel.Value.ToString(); }
            set
            {
                _colorLevel.Value = Convert.ToDouble(value);
                OnPropertyChanged("Value");
            }
        }
        
        #endregion // Свойства

        #region Конструкторы

        public ColorLevelViewModel()
        {
            _colorLevel.Value = 0.0;
            _colorLevel.Color = System.Windows.Media.Color.FromArgb(255,255,255,255);
        }

        public ColorLevelViewModel(Color color, double value)
        {
            _colorLevel.Color = color;

            if (value >= 0.0 && value <= 1.0)
                _colorLevel.Value = value;
            else
                throw new Exception(string.Format("Color {1} have value {0}!", value, color));
        }

        #endregion // Конструкторы


    }
}
